var serverSend = 'LC:'+
			'{"Type":0,"NName":"19","Name":"19",'+
				'"ArrCard":[{"N":5,"S":1},{"N":5,"S":2},{"N":5,"S":3},'+
							'{"N":1,"S":1},{"N":6,"S":1},{"N":6,"S":2},'+
							'{"N":6,"S":3},{"N":1,"S":4},{"N":1,"S":2}'+
							']'+			
			'}';
			
function processServerSend(){
	var index = serverSend.indexOf(':');
	if(serverSend.substr(0,index)=="LC"){
		start(serverSend.substr(index+1,serverSend.length));
	}
	
}

function processDataFromServer(str){ 
	//Xu ly cac chuoi nhan ve tu Server ==> Phan luong
	if (str == "0") return ;
	//tf.appendText("\n userinfo: " + str);
	if (str.search("WC:") == 0) {
		var obj = JSON.decode(str.substring(3));
		user.PlayId = obj.PlayId;//str.substring(3).split('^')[2];
		currPlayer.PlayerID = user.PlayId ;
		currPlayer.PlayerName = obj.PlayName ;
		if (obj.Level == undefined)
		{
			currPlayer.Level = "99" ;
		}else
		{
			currPlayer.Level = obj.Level;
		}
		//currPlayer.Level = ;
		currPlayer.PlayerIP = obj.sIP ;
		currPlayer.Mark = obj.Mark ;
		currPlayer.ArrCard = new Array() ;
		currPlayer.ArrMovie = new Array() ;
		currPlayer.ArrCardDow = new Array() ;
		currPlayer.ArrMovieDow = new Array() ;
		currPlayer.ArrCardRemove = new Array() ;
		currPlayer.ArrMovieRemove = new Array() ;
		mainStage_mc.gotoAndStop(2);
		var obj1 = new Object();
		obj1.Username = currPlayer.PlayerName;
		ExternalInterface.call("CallPromotion", JSON.encode(obj1));
		//var obj2:Object = new Object();
		//obj2.Username = user.Username;
		//ExternalInterface.call("DayPromotion", JSON.encode(obj2));
		if (currPlayer.Level == 0 || currPlayer.Level ==1 ) {
			TutLoad();
		}
	}
	if (str.search("DC:") == 0) { //Player khac danh bai	
		if (mainStage_mc.currentFrame == 5)
			OtherRemoveCard(str.substring(3)) ;
	} else if (str.search("BC:") == 0) { //Boc bai
		if (mainStage_mc.currentFrame == 5)
			OtherAddCard(str.substring(3)) ;
	} else if (str.search("AC:") == 0) { //An bai
		if (mainStage_mc.currentFrame == 5)
			OtherTakeCard(str.substring(3)) ;
	} else if (str.search("HC:") == 0) { //Ha bai
		if (mainStage_mc.currentFrame == 5)
			OtherDownCard(str.substring(3)) ;
	} else if (str.search("GC:") == 0) { //Gui bai
		if (mainStage_mc.currentFrame == 5)
			OtherAttachCard(str.substring(3)) ;
	} else if (str.search("AL:") == 0) { //Gia tri tra ve sau khi ket noi thanh cong ==> Danh sach Level
		//if (mainStage_mc.currentFrame <= 4)
			initLevelRoom(str.substring(3));				
	} else if (str.search("AR:") == 0) { //Danh sach phong tra ve Add Room sau khi click chon Level
		//if (mainStage_mc.currentFrame <= 5)
			initRoom(str.substring(3));
	} else if (str.search("AT:") == 0) { //Add Table ==> Danh sach ban tra ve				
		if (mainStage_mc.currentFrame == 4)
			initTable(str.substring(3));				
	} 
	else if (str.search("CT:") == 0) { //Create Table
		if (mainStage_mc.currentFrame == 4)
			CreateTable(str.substring(3)) ; 				
	} else if (str.search("RG:") == 0) { //Player khac gui thong bao san sang
		if (mainStage_mc.currentFrame == 5)
			ReadyTable(str.substring(3)) ;
	} else if (str.search("JT:") == 0) { //Join Table
		if ((mainStage_mc.currentFrame == 5) || (mainStage_mc.currentFrame == 4))
			JoinTable(str.substring(3)) ;				
	} else if (str.search("LC:") == 0) { //Khoi tao ban choi
		if (mainStage_mc.currentFrame == 5)
			InitGame(str.substring(3)) ;
	} else if (str.search("VP:") == 0) { //Other Join Table
		if (mainStage_mc.currentFrame == 5)
			OtherJoinTable(str.substring(3)) ;				
	} else if (str.search("LT:") == 0) { //Player roi ban
		if (mainStage_mc.currentFrame == 5)
			ExitTable(str.substring(3)) ;
	} else if (str.search("DT:") == 0) { //Nguoi tao ra ban ban thoat
		if (mainStage_mc.currentFrame == 5)
			ExitTable(str.substring(3)) ;
	} else if (str.search("FG:") == 0) {
		if (mainStage_mc.currentFrame == 5) 
			FinishedGame(str.substring(3)) ;
	} else if (str.search("VT:") == 0) {
		//tf.appendText("==>Get:" + str) ;
		if (mainStage_mc.currentFrame == 4)
			ViewTable(str.substring(3)) ;
	} else if (str.search("DIT:") == 0) {
		if (mainStage_mc.currentFrame == 4)
			DeleteTable(str.substring(4)) ;
	} else if (str.search("AM:") == 0) {
		UpdateMoney(str.substring(3)) ;
	} else if (str.search("MSGT:") == 0) {				
		ResultTransferAG(str.substring(5)) ;
	} else if (str.search("MSG:") == 0) {
		showMSG(str.substring(4)) ;
	} else if (str.search("SKR") == 0) {				
		isKickRoom = true ;
	} 
}

function jsonStart(strStart){
	var objStart = JSON.parse(strStart);
	var _type = objStart.Type;
	var _nName = objStart.NName;
	var _name = objStart.Name;
	var _arrNumId = [];
	var _arrSuitId = [];
	for(var i=0;i<objStart.ArrCard.length;i++){
		_arrNumId.push(objStart.ArrCard[i].N);
		_arrSuitId.push(objStart.ArrCard[i].S);
	}
	var re = [_type, _nName, _name, _arrNumId, _arrSuitId];
	return re;
}

function jsonInfo(strInfo){
	var objInfo = JSON.parse(strInfo);
	var _id = objInfo.PlayId;
	var _name = objInfo.PlayName;
	var _ag = objInfo.Mark;
	var _ip = objInfo.sIP;
	for(var i=0;i<objStart.ArrCard.length;i++){
		_arrNumId.push(objStart.ArrCard[i].N);
		_arrSuitId.push(objStart.ArrCard[i].S);
	}
	var re = [_type, _nName, _name, _arrNumId, _arrSuitId];
	return re;
}

